package adim;

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.wireless.messaging.*;
import java.io.IOException;

public class Utils {

	public static void sendSMS(String msg, String addr)
	{
		String fullAddr = "sms://" + addr;

		try {
			MessageConnection c = (MessageConnection)Connector.open(fullAddr);

			TextMessage tm = (TextMessage) c.newMessage(MessageConnection.TEXT_MESSAGE);
			tm.setPayloadText(msg);

			c.send(tm);
			c.close();

		} catch (IOException ioe) {
			System.out.println("exception: " + ioe.toString());
		}
	}

	public static void newSendSMS(String msg, String addr)
	{
		String fullAddr = "sms://" + addr;

		try {
			MessageConnection c = (MessageConnection)Connector.open(fullAddr);

			System.out.println(MessageConnection.TEXT_MESSAGE);
			TextMessage tm = (TextMessage) c.newMessage("text");
			tm.setPayloadText(msg);

			c.send(tm);
			c.close();

		} catch (IOException ioe) {
			System.out.println("exception: " + ioe.toString());
		}
	}

	public static void showError(AppScreen as, String msg) 
	{
		Alert al = new Alert("Error!", msg, null, AlertType.ERROR);
		as.setCurrentDisplay(al);
	}

}
